import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QComboBox, QPushButton


class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("PyQt5 ComboBox Example")
        self.setGeometry(100, 100, 300, 200)

        # 创建一个垂直布局
        self.layout = QVBoxLayout()
        self.setLayout(self.layout)

        # 创建一个下拉框
        self.combo_box = QComboBox()
        self.layout.addWidget(self.combo_box)

        # 添加待选值
        self.combo_box.addItem("1")
        self.combo_box.addItem("2")
        self.combo_box.addItem("3")

        # 创建按钮
        self.button = QPushButton("获取选中值")
        self.button.clicked.connect(self.show_choose_value)
        self.layout.addWidget(self.button)

    def show_choose_value(self):
        print(self.combo_box.currentText())


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())
